package com.mav.controller;

import com.mav.pojo.PageResult;
import com.mav.pojo.Result;
import com.mav.pojo.Student;
import com.mav.pojo.StudentQueryParam;
import com.mav.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    StudentService studentService;
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam){
        log.info("页面请求参数:{}",studentQueryParam);
        PageResult<Student> pageResult = studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("要删除学生的id:{}",ids);
        studentService.deleteById(ids);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Student student){
        log.info("要添加的学生:{}",student);
        studentService.add(student);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        log.info("按照员工id查找,id:{}",id);
        Student student=studentService.findById(id);
        return Result.success(student);
    }
    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("更新学生信息:{}",student);
        studentService.updateById(student);
        return Result.success();
    }
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id,@PathVariable Short score){
        studentService.disciplinaryViolation(id,score);
        return Result.success();
    }
}
